//  åä¸ä¾èµåèåè¿æ»¤ã
//  è·åå½åè¡å½ååä¹åéç½®çæ°æ®ç»å®ååã
function getDataSourcesTableByBindTableIndex(tables, bindTableIndex) {
  for (var i = 0; i < tables.length; i++) {
    if (tables[i].TableIndex == bindTableIndex) {
      return i
    }
  }
  return null
}
function getReferColumnNameSelect() {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]
  var cell = segment.Rows[this.currentCell.RowIndex].Cells[this.currentCell.ColumnIndex]

  var dataSourceIndex = this.getReportDataSourceIndex(this.currentPageIndex)

  var entities = []
  if (segment.IsBindData) {
    if (styleSourceID == '1' && dataSourceIndex != null && this.report.DataSources[dataSourceIndex].Tables != null && this.report.DataSources[dataSourceIndex].Tables[segment.BindTableIndex] != null) {
      var tableIndex = this.getDataSourcesTableByBindTableIndex(this.report.DataSources[dataSourceIndex].Tables, segment.BindTableIndex)
      if (tableIndex != null) {
        var table = this.report.DataSources[dataSourceIndex].Tables[tableIndex]
        if (table.Columns != null) {
          for (var i = 0; i < this.currentCell.ColumnIndex; i++) {
            if (segment.Rows[this.currentCell.RowIndex].Cells[i].ColumnName != null &&
              (segment.Rows[this.currentCell.RowIndex].Cells[i].IfSameMarge == 1 || segment.Rows[this.currentCell.RowIndex].Cells[i].IfSameMarge == 3)) {
              var referColumnName = { ID: segment.Rows[this.currentCell.RowIndex].Cells[i].ColumnName }
              var isFind = false
              for (var j = 0; j < table.Columns.length; j++) {
                if (table.Columns[j].ColumnName == segment.Rows[this.currentCell.RowIndex].Cells[i].ColumnName) {
                  referColumnName.Name = table.Columns[j].ColumnDescribe
                  isFind = true
                }
              }
              if (isFind == false) {
                referColumnName.Name = segment.Rows[this.currentCell.RowIndex].Cells[i].ColumnName
              }

              entities.push(referColumnName)
            }
          }
        }
      }
    } else {
      for (var i = 0; i < this.currentCell.ColumnIndex; i++) {
        if (segment.Rows[this.currentCell.RowIndex].Cells[i].ColumnName != null && (segment.Rows[this.currentCell.RowIndex].Cells[i].IfSameMarge == 1 || segment.Rows[this.currentCell.RowIndex].Cells[i].IfSameMarge == 3)) {
          entities.push({ ID: segment.Rows[this.currentCell.RowIndex].Cells[i].ColumnName, Name: segment.Rows[this.currentCell.RowIndex].Cells[i].ColumnName })
        }
      }
    }
  }

  return entities
}

//  æ ¹æ®å½åé¡µé¢ç´¢å¼åç»å®æ°æ®æºç´¢å¼ï¼æå»ºæ°æ®æºç»æåä¸æå®ä½ã
function getDataSourceColumnSelect() {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]

  var entities = []
  var dataSourceIndex = this.getReportDataSourceIndex(this.currentPageIndex)

  if (segment.IsBindData) {
    if (styleSourceID == '0' && dataSourceIndex != null && this.report.DataSources[dataSourceIndex] != null) {
      var res = Tsxd.Ajax.invoke('MBS.BL.HtmlReport.GetColumnNamesByDataSource', [this.report.DataSources[dataSourceIndex], segment.DataTableIndex])
      if (System.CheckResult(res) == false) return entities

      for (var i = 0; i < res.value.length; i++) {
        entities.push({ ID: res.value[i], Name: res.value[i] })
      }
    }

    if (styleSourceID == '1' && dataSourceIndex != null && this.report.DataSources[dataSourceIndex].Tables != null && this.report.DataSources[dataSourceIndex].Tables[segment.BindTableIndex] != null) {
      var tableIndex = this.getDataSourcesTableByBindTableIndex(this.report.DataSources[dataSourceIndex].Tables, segment.BindTableIndex)
      if (tableIndex != null) {
        var table = this.report.DataSources[dataSourceIndex].Tables[tableIndex]
        if (table.Columns != null) {
          for (var i = 0; i < table.Columns.length; i++) {
            entities.push({ ID: table.Columns[i].ColumnName, Name: table.Columns[i].ColumnDescribe })
          }
        }
      }
    }
  }

  return entities
}

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/* åå¹¶æ ¼ */
//  å¼¹åºå½å¥åå³åä¸åå¹¶æ ¼æ°çªå£ã
function mergeCell() {
  if (isUpdate == null) return //  æµè§ç¶æã
  CellMergeOkBtn.setVisible(true)
  CellMergeCancelBtn.setVisible(true)

  CellMergeOkBtn.onClickFunction = 'affirmMergeCell'
  CellMergeCancelBtn.onClickFunction = 'cancelMergeCell'

  $('CellRightMergeColumns').setValue(0)
  $('CellDownMergeRows').setValue(0)

  var dialogConfig = { Title: 'ååæ ¼åå¹¶', Target: $('CellMergeSetDiv'), Width: 220, Height: 100, Function: null, IsModal: true }
  perSaveDialog = Dialog.open(dialogConfig)
}

//  è·åæå®åå¹¶æ ¼æ°ï¼å¨æå®åºé´åå¨è·ååºé´åè½å¤åå¹¶çæå¤§åºåã
function getCellCoalitionArea() {
  var rightColumns = $('CellRightMergeColumns').getValue(true, true)
  if (rightColumns == null) return false
  var downRows = $('CellDownMergeRows').getValue(true, true)
  if (downRows == null) return false

  var segmentPositionName = this.getSegmentPositionName(this.currentSegment.SegmentPosition)
  var rowCount = report.Pages[this.currentPageIndex][segmentPositionName][this.currentSegment.SegmentIndex].Rows.length - 1
  var columnCount = report.Pages[this.currentPageIndex][segmentPositionName][this.currentSegment.SegmentIndex].Rows[this.currentCell.RowIndex].Cells.length - 1

  var tempDownMergeRows = this.getCellDownMergeRows(downRows, rowCount)
  if (tempDownMergeRows == false) return false
  var tempRightMergeRows = this.getCellRightMergeColumns(rightColumns, columnCount)
  if (tempRightMergeRows == false) return false

  var mergeRowIndex = this.currentCell.RowIndex + tempDownMergeRows - 1
  var mergeColumnIndex = this.currentCell.ColumnIndex + tempRightMergeRows - 1

  return this.getCellMergeMaxArea(this.currentCell.RowIndex, this.currentCell.ColumnIndex, mergeRowIndex, mergeColumnIndex)
}

//  åå¹¶åºååå¦æå­å¨åå¹¶éç¹çï¼æç§éç¹åå¹¶çåºåéªè¯æ¯å¦è¶åºæå®çç»æä½ç½®ï¼å¦æè¶åºï¼è¿åè¯¥éç¹ç»æä½ç½®åæ åºåã
//  å¤çéç¹ååæ ¼ã
//  startRow    å¼å§è¡ç´¢å¼ã
//  startColumn     å¼å§åç´¢å¼ã
//  endRow  ç»æè¡ç´¢å¼ã
//  endColumn   ç»æåç´¢å¼ã
//  anchorRow   åå¹¶æ ¼éç¹è¡ç´¢å¼ã
//  anchorColumn åå¹¶æ ¼éç¹åç´¢å¼ã
//  è¿åç»æã
//  return null æ²¡æè¶åºç°æåºåã
//  return Range è¶åºåçæ°åºåã
function getCellMergeMaxAreaByEnd(startRow, startColumn, endRow, endColumn, anchorRow, anchorColumn) {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]

  if ((anchorColumn + segment.Rows[anchorRow].Cells[anchorColumn].ColumnSpan - 1) > endColumn) {
    return this.getCellMergeMaxArea(startRow, startColumn, endRow, anchorColumn + segment.Rows[anchorRow].Cells[anchorColumn].ColumnSpan - 1)
  }
  if ((anchorRow + segment.Rows[anchorRow].Cells[anchorColumn].RowSpan - 1) > endRow) {
    return this.getCellMergeMaxArea(startRow, startColumn, anchorRow + segment.Rows[anchorRow].Cells[anchorColumn].RowSpan - 1, endColumn)
  }
  return null
}

//  åå¹¶åºååå¦æå­å¨åå¹¶éç¹çï¼æç§åå¹¶æ ¼å¯¹åºçéç¹éªè¯æ¯å¦è¶åºæå®çåºåçå¼å§ä½ç½®ï¼å¦æè¶åºï¼è¿åè¶åºé¨åçæ°å¼å§ä½ç½®çåºååæ ã
//  å¤çåå¹¶ååæ ¼ã
//  startRow    å¼å§è¡ç´¢å¼ã
//  startColumn     å¼å§åç´¢å¼ã
//  endRow  ç»æè¡ç´¢å¼ã
//  endColumn   ç»æåç´¢å¼ã
//  anchorRow   åå¹¶æ ¼éç¹è¡ç´¢å¼ã
//  anchorColumn åå¹¶æ ¼éç¹åç´¢å¼ã
//  è¿åç»æã
//  return null æ²¡æè¶åºç°æåºåã
//  return Range è¶åºåçæ°åºåã
function getCellMergeMaxAreaByStart(startRow, startColumn, endRow, endColumn, anchorRow, anchorColumn) {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]

  if (startColumn > anchorColumn) {
    return this.getCellMergeMaxArea(startRow, anchorColumn, endRow, endColumn)
  }
  if (startRow > anchorRow) {
    return this.getCellMergeMaxArea(anchorRow, startColumn, endRow, endColumn)
  }
  if (anchorColumn + segment.Rows[anchorRow].Cells[anchorColumn].ColumnSpan - 1 > endColumn) {
    return this.getCellMergeMaxArea(startRow, startColumn, endRow, anchorColumn + segment.Rows[anchorRow].Cells[anchorColumn].ColumnSpan - 1)
  }
  if (anchorRow + segment.Rows[anchorRow].Cells[anchorColumn].RowSpan - 1 > endRow) {
    return this.getCellMergeMaxArea(startRow, startColumn, anchorRow + segment.Rows[anchorRow].Cells[anchorColumn].RowSpan - 1, endColumn)
  }
  return null
}

//  è·åååæ ¼åå¹¶æå¤§åºåèå´Rangeã
//  å¤çåå¹¶ååæ ¼ã
//  startRow    å¼å§è¡ç´¢å¼ã
//  startColumn     å¼å§åç´¢å¼ã
//  endRow  ç»æè¡ç´¢å¼ã
//  endColumn   ç»æåç´¢å¼ã
//  è¿åç»æã
//  return Range å¦ææ²¡è¶åºæå®åºåè¿åæå®åºåã
function getCellMergeMaxArea(startRow, startColumn, endRow, endColumn) {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]

  //  ç¬¬ä¸è¡
  for (var i = startColumn; i <= endColumn; i++) {
    if (segment.Rows[startRow].Cells[i].IsAnchor == true) {
      var range = this.getCellMergeMaxAreaByEnd(startRow, startColumn, endRow, endColumn, startRow, i)
      if (range != null) return range
    }
    if (segment.Rows[startRow].Cells[i].IsMerge == true) {
      var range = this.getCellMergeMaxAreaByStart(startRow, startColumn, endRow, endColumn, segment.Rows[startRow].Cells[i].AnchorX, segment.Rows[startRow].Cells[i].AnchorY)
      if (range != null) return range
    }
  }
  // ç¬¬ä¸å
  for (var i = startRow; i <= endRow; i++) {
    if (segment.Rows[i].Cells[startColumn].IsAnchor == true) {
      var range = this.getCellMergeMaxAreaByEnd(startRow, startColumn, endRow, endColumn, i, startColumn)
      if (range != null) return range
    }
    if (segment.Rows[i].Cells[startColumn].IsMerge == true) {
      var range = this.getCellMergeMaxAreaByStart(startRow, startColumn, endRow, endColumn, segment.Rows[i].Cells[startColumn].AnchorX, segment.Rows[i].Cells[startColumn].AnchorY)
      if (range != null) return range
    }
  }
  // æ«è¡
  for (var i = startColumn; i <= endColumn; i++) {
    if (segment.Rows[endRow].Cells[i].IsAnchor == true) {
      var range = this.getCellMergeMaxAreaByEnd(startRow, startColumn, endRow, endColumn, endRow, i)
      if (range != null) return range
    }
    if (segment.Rows[endRow].Cells[i].IsMerge == true) {
      var range = this.getCellMergeMaxAreaByStart(startRow, startColumn, endRow, endColumn, segment.Rows[endRow].Cells[i].AnchorX, segment.Rows[endRow].Cells[i].AnchorY)
      if (range != null) return range
    }
  }
  // æ«å
  for (var i = startRow; i <= endRow; i++) {
    if (segment.Rows[i].Cells[endColumn].IsAnhor == true) {
      var range = this.getCellMergeMaxAreaByEnd(startRow, startColumn, endRow, endColumn, i, endColumn)
      if (range != null) return range
    }
    if (segment.Rows[i].Cells[endColumn].IsMerge == true) {
      var range = this.getCellMergeMaxAreaByStart(startRow, startColumn, endRow, endColumn, segment.Rows[i].Cells[endColumn].AnchorX, segment.Rows[i].Cells[endColumn].AnchorY)
      if (range != null) return range
    }
  }

  return { StartPair: { X: startRow, Y: startColumn }, EndPair: { X: endRow, Y: endColumn }}
}

//  è·ååä¸åå¹¶çåæ°ã
//  downRows    åä¸åå¹¶çè¡æ°ã
//  rowCount    å½åæ®µè½æ»è¡æ°ã
function getCellDownMergeRows(downRows, rowCount) {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]
  var cell = segment.Rows[this.currentCell.RowIndex].Cells[this.currentCell.ColumnIndex]

  var mergeRows = cell.RowSpan
  for (j = 1; j <= downRows; j++) {
    //  åä¸éè¡å¤æ­æ¯å¦è¶åºè¾¹ç ã
    if (cell.RowIndex + mergeRows >= segment.Rows.length) {
      alert('è¶åºè¾¹çã')
      return
    }
    //  éè¡éªè¯å½åä½ç½®ååæ ¼çåå¹¶è¡æ°ï¼è®¡ç®åºåä¸çåå¹¶åæ°å
    mergeRows = mergeRows + segment.Rows[cell.RowIndex + mergeRows].Cells[cell.ColumnIndex].RowSpan
    //  å¤æ­æ¯å¦ä¸ç§»åçåä¸æ ¼çè¡ç´¢å¼æ¯å¦è¶åºæ»è¡æ°äºï¼å¦æè¶åºï¼è¿åæåä¸è¡å°éä¸­è¡çåå¹¶çè¡æ°ã
    if (segment.Rows[cell.RowIndex + mergeRows - 1].Cells[cell.ColumnIndex].RowIndex >= rowCount) {
      return rowCount - cell.RowIndex + 1
    }
  }
  return mergeRows
}

//  è·ååå³åå¹¶çåæ°ã
//  rightColumns    åå³åå¹¶çåæ°ã
//  columnCount     å½åè¡æ»åæ°ã
function getCellRightMergeColumns(rightColumns, columnCount) {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]
  var cell = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex].Rows[this.currentCell.RowIndex].Cells[this.currentCell.ColumnIndex]

  var mergeColumns = cell.ColumnSpan

  for (j = 1; j <= rightColumns; j++) {
    if (cell.ColumnIndex + mergeColumns >= segment.Rows[this.currentCell.RowIndex].Cells.length) {
      alert('è¶åºè¾¹çã')
      return false
    }
    mergeColumns = mergeColumns + segment.Rows[this.currentCell.RowIndex].Cells[cell.ColumnIndex + mergeColumns].ColumnSpan
    if (segment.Rows[this.currentCell.RowIndex].Cells[cell.ColumnIndex + mergeColumns - 1].ColumnIndex >= columnCount) {
      return columnCount - cell.ColumnIndex + 1
    }
  }
  return mergeColumns
}
//  æç§éç¹ä¿¡æ¯è®¾ç½®åå¹¶ååæ ¼ã
//  segment å½åæ®µè½ã
//  row å½åè¡ç´¢å¼ã
//  column å½ååç´¢å¼ã
//  anchor æ¯å¦éç¹
//  merge æ¯å¦åå¹¶æ ¼ã
//  anchorX éç¹è¡ç´¢å¼ã
//  anchorY éç¹åç´¢å¼ã
//  columnSpan ååå¹¶æ°ã
//  rowSpan  è¡åå¹¶æ°ã
function setCellByAnchorMerge(segment, row, column, anchor, merge, anchorX, anchorY, columnSpan, rowSpan) {
  segment.Rows[row].Cells[column].IsAnchor = anchor
  segment.Rows[row].Cells[column].IsMerge = merge
  segment.Rows[row].Cells[column].AnchorX = anchorX
  segment.Rows[row].Cells[column].AnchorY = anchorY
  segment.Rows[row].Cells[column].ColumnSpan = columnSpan
  segment.Rows[row].Cells[column].RowSpan = rowSpan
}

//  æ ¹æ®Segmentä¸­çåå¹¶ä½ç½®è·åHTMLè¡¨æ ¼ä¸­çå®éåå¹¶ç´¢å¼åã
//  segment å½åæ®µè½ã
//  rowIndex æ®µè½çå½åè¡ä½ç½®ã
//  columnIndex æ®µè½çå½ååä½ç½®ã
//  è¿åå¼ï¼HTMLé¡µé¢ä¸­Tableçç´¢å¼ä½ç½®ã
function getHTMLTableInsertColumnIndex(segment, rowIndex, columnIndex) {
  var insertColumnIndex = 0
  for (var i = 0; i < columnIndex; i++) {
    if (segment.Rows[rowIndex].Cells[i].IsMerge == false) {
      insertColumnIndex++
    }
  }
  return insertColumnIndex
}

//  æç§æ°çåå¹¶åºååå¹¶ååæ ¼ã
//  segment å½åæ®µè½ã
//  range åå¹¶åºå
function mergeCellByRange(segment, range) {
  //  åæåå¹¶åºååçåå¹¶æ ¼åæå
  for (var i = range.StartPair.X; i <= range.EndPair.X; i++) {
    for (var j = range.StartPair.Y; j <= range.EndPair.Y; j++) {
      if (segment.Rows[i].Cells[j].IsAnchor == true) {
        this.affirmSplitCell(segment, segment.Rows[i].Cells[j])
      }
    }
  }

  var table = $(segment.Name).lastChild

  var mergeMaxWidth = 0 //  æå¤§çåå¹¶æ ¼å®½åº¦ã
  var mergeMaxHeight = 0 //  æå¤§çåå¹¶æ ¼é«åº¦ã
  var mergeWidth = 0 //  åå¹¶æ ¼å®½åº¦ã
  var mergeHeight = 0 //  åå¹¶æ ¼é«åº¦ã
  var tableMergeColumnIndex = 0 //   Htmlé¡µé¢ä¸­Tableå¯¹åºä½ç½®åç´¢å¼ã

  for (var i = range.StartPair.X; i <= range.EndPair.X; i++) {
    mergeWidth = 0
    for (var j = range.StartPair.Y; j <= range.EndPair.Y; j++) {
      //  è®¾ç½®éç¹ãè®¾ç½®åå¹¶ãè®¾ç½®éç¹ä½ç½®ã
      if (i == range.StartPair.X && j == range.StartPair.Y) {
        this.setCellByAnchorMerge(segment, i, j, true, false, 0, 0, range.EndPair.Y - range.StartPair.Y + 1, range.EndPair.X - range.StartPair.X + 1)

        mergeWidth = ET.sum(ET.sum(ET.sum(ET.sum(segment.Rows[i].Cells[j].Width, segment.Rows[i].Cells[j].Border.Left), segment.Rows[i].Cells[j].Border.Right), segment.Rows[i].Cells[j].Padding.Left), segment.Rows[i].Cells[j].Padding.Right)
        mergeHeight = ET.sum(ET.sum(ET.sum(ET.sum(segment.Rows[i].Cells[j].Height, segment.Rows[i].Cells[j].Border.Top), segment.Rows[i].Cells[j].Border.Bottom), segment.Rows[i].Cells[j].Padding.Top), segment.Rows[i].Cells[j].Padding.Bottom)

        //  è°æ´è¡¨æ ¼ä¸­æ°åå¹¶æ ¼ã
        tableMergeColumnIndex = this.getHTMLTableInsertColumnIndex(segment, i, j)
        table.rows[i].cells[tableMergeColumnIndex].colSpan = segment.Rows[i].Cells[j].ColumnSpan
        table.rows[i].cells[tableMergeColumnIndex].rowSpan = segment.Rows[i].Cells[j].RowSpan
      } else {
        this.setCellByAnchorMerge(segment, i, j, false, true, range.StartPair.X, range.StartPair.Y, 1, 1)

        tableMergeColumnIndex = this.getHTMLTableInsertColumnIndex(segment, i, j)
        table.rows[i].cells[tableMergeColumnIndex].removeNode(true)

        mergeWidth = ET.sum(ET.sum(ET.sum(ET.sum(ET.sum(mergeWidth, segment.Rows[i].Cells[j].Width), segment.Rows[i].Cells[j].Border.Left), segment.Rows[i].Cells[j].Border.Right), segment.Rows[i].Cells[j].Padding.Left), segment.Rows[i].Cells[j].Padding.Right)
        var tempHeight = ET.sum(ET.sum(ET.sum(ET.sum(segment.Rows[i].Cells[j].Height, segment.Rows[i].Cells[j].Border.Top), segment.Rows[i].Cells[j].Border.Bottom), segment.Rows[i].Cells[j].Padding.Top), segment.Rows[i].Cells[j].Padding.Bottom)

        if (mergeHeight < tempHeight) {
          mergeHeight = tempHeight
        }
      }
    }

    mergeMaxHeight = ET.sum(mergeMaxHeight, mergeHeight)

    if (mergeMaxWidth < mergeWidth) {
      mergeMaxWidth = mergeWidth
    }
  }

  var tempCell = segment.Rows[range.StartPair.X].Cells[range.StartPair.Y]
  tempCell.Width = ET.sub(ET.sub(ET.sub(ET.sub(mergeMaxWidth, tempCell.Border.Left), tempCell.Border.Right), tempCell.Padding.Left), tempCell.Padding.Right)
  tempCell.Height = ET.sub(ET.sub(ET.sub(ET.sub(mergeMaxHeight, tempCell.Border.Top), tempCell.Border.Bottom), tempCell.Padding.Top), tempCell.Padding.Bottom)

  tableMergeColumnIndex = this.getHTMLTableInsertColumnIndex(segment, range.StartPair.X, range.StartPair.Y)
  table.rows[range.StartPair.X].cells[tableMergeColumnIndex].style.width = tempCell.Width + 'mm'
  table.rows[range.StartPair.X].cells[tableMergeColumnIndex].style.height = tempCell.Height + 'mm'

  mergeMaxWidth = null
  mergeMaxHeight = null
  mergeWidth = null
  mergeHeight = null
}

//  åå¹¶ååæ ¼ç¡®è®¤æé®è§¦åäºä»¶ã
function affirmMergeCell() {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]

  var range = this.getCellCoalitionArea()
  if (range == false) return

  this.mergeCellByRange(segment, range)

  var dialogConfig = { Title: 'ååæ ¼åå¹¶', Target: $('CellMergeSetDiv'), Width: 220, Height: 100, Function: null, IsModal: true }
  Dialog.close(dialogConfig)
}

//  åå¹¶ååæ ¼åæ¶æé®è§¦åäºä»¶ã
function cancelMergeCell() {
  var dialogConfig = { Title: 'ååæ ¼åå¹¶', Target: $('CellMergeSetDiv'), Width: 220, Height: 100, Function: null, IsModal: true }
  Dialog.close(dialogConfig)
}
//  è·åæåååæ ¼å½åä½ç½®çæ ¼é«ã
//  segment å½åæ®µè½ã
//  curRowIndex å½åæåååæ ¼è¡ç´¢å¼ã
function getCellHeightForSplit(segment, curRowIndex) {
  for (var i = 0; i < segment.Rows[curRowIndex].Cells.length; i++) {
    if (segment.Rows[curRowIndex].Cells[i].IsAnchor == false && segment.Rows[curRowIndex].Cells[i].IsMerge == false) {
      return segment.Rows[curRowIndex].Cells[i].Height
    }
  }
  for (var i = 0; i < segment.Rows[curRowIndex].Cells.length; i++) {
    if (segment.Rows[curRowIndex].Cells[i].IsMerge == true) {
      return segment.Rows[curRowIndex].Cells[i].Height
    }
  }
  return 0
}

//  è·åæåååæ ¼å½åä½ç½®çæ ¼å®½ã
//  segment å½åæ®µè½ã
//  curRowIndex å½åæåååæ ¼è¡ç´¢å¼ã
//  curColumnIndex å½åæåååæ ¼åç´¢å¼ã
function getCellWidthForSplit(segment, curRowIndex, curColumnIndex) {
  for (var i = 0; i < segment.Rows.length; i++) {
    if (segment.Rows[i].Cells[curColumnIndex].IsAnchor == false && segment.Rows[i].Cells[curColumnIndex].IsMerge == false) {
      return segment.Rows[i].Cells[curColumnIndex].Width
    }
  }

  for (var i = 0; i < segment.Rows.length; i++) {
    if (segment.Rows[i].Cells[curColumnIndex].IsMerge == true) {
      return segment.Rows[i].Cells[curColumnIndex].Width
    }
  }
  return 0
}
//  ç¡®è®¤ååæ ¼æåã
//  segment å½åæ®µè½ã
//  cell    å½åæåçååæ ¼ã
function affirmSplitCell(segment, cell) {
  //  å¨æå¼ã
  var rows = cell.RowIndex + cell.RowSpan
  var columns = cell.ColumnIndex + cell.ColumnSpan

  for (var i = cell.RowIndex; i < rows; i++) {
    for (var j = cell.ColumnIndex; j < columns; j++) {
      segment.Rows[i].Cells[j].Width = this.getCellWidthForSplit(segment, i, j) // 0;
      segment.Rows[i].Cells[j].Height = this.getCellHeightForSplit(segment, i)

      segment.Rows[i].Cells[j].IsAnchor = false
      segment.Rows[i].Cells[j].IsMerge = false
      segment.Rows[i].Cells[j].AnchorX = 0
      segment.Rows[i].Cells[j].AnchorY = 0
      segment.Rows[i].Cells[j].ColumnSpan = 1
      segment.Rows[i].Cells[j].RowSpan = 1
    }
  }

  var table = $(segment.Name).lastChild
  var splitStatus = false
  //
  for (var i = 0; i < table.rows.length; i++) {
    for (var j = 0; j < table.rows[i].cells.length; j++) {
      var cellPosition = table.rows[i].cells[j].id.split('_')
      var cellX = parseInt(cellPosition[cellPosition.length - 2])
      var cellY = parseInt(cellPosition[cellPosition.length - 1])

      //  æ¥æ¾å°ç¬¬ä¸ä¸ªæ»¡è¶³å½åæ ¼ä½ç½®çCellã
      if (cellX == cell.RowIndex && cellY == cell.ColumnIndex) {
        var splitCellRowSpan = table.rows[i].cells[j].rowSpan
        var splitCellColSpan = table.rows[i].cells[j].colSpan

        //  ä»å¼å§ä½ç½®ï¼æååºæ°çååæ ¼æ ¼ã
        for (var m = i; m < i + splitCellRowSpan; m++) {
          for (var n = j; n < j + splitCellColSpan; n++) {
            if (m == i && n == j) //  å½åæ ¼è®¾ç½®æ åå¹¶è¡ä¸åã
            {
              table.rows[m].cells[n].rowSpan = 1
              table.rows[m].cells[n].colSpan = 1
              //  å®½ä¸é«çå¤çã
              this.onDrawCell(table.rows[m].cells[n], segment, segment.Rows[i].Cells[j])
            } else //  éå½åæåæ ¼ï¼éè¦å¾Tableä¸­å¢å æ°çæåæ ¼ã
            {
              if (m >= table.rows.length) {
                var newRowElement = table.insertRow(m)
              }

              var newCell = table.rows[m].insertCell(this.getHTMLTableInsertColumnIndex(segment, m, n))
              newCell.id = segment.Name + '_' + (cellX + m - i) + '_' + (cellY + n - j)
              newCell.onfocus = function() { oldCellBackGroundColor = this.style.backgroundColor; this.style.backgroundColor = '#F5ECBE' }
              newCell.onblur = function() { this.style.backgroundColor = oldCellBackGroundColor }

              //  ä¿®æ¹Tableä¸­çååæ ¼æ¾ç¤ºæ ¼å¼ã
              this.onDrawCell(newCell, segment, segment.Rows[cellX + m - i].Cells[cellY + n - j])
            }
          }
        }
        splitStatus = true
        break
      }
      if (splitStatus) {
        break
      }
    }
  }
}

/* æåæ ¼ */
function splitCell() {
  if (isUpdate == null) return //  æµè§ç¶æã
  if (this.currentCell == null || this.currentCell.RowIndex == null) {
    alert('è¯·éæ©è¦æåçååæ ¼ã')
    return
  }
  if (confirm('ççè¦æåååæ ¼åï¼') == false) {
    return
  }

  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]
  var cell = segment.Rows[this.currentCell.RowIndex].Cells[this.currentCell.ColumnIndex]

  //  ç¡®è®¤æåååæ ¼ã
  this.affirmSplitCell(segment, cell)
}
// è°æ´å½åéä¸­è¡è¡é«ã
//  å¼¹åºè¡é« ä¿®æ¹çªå£
function modifyRowHeight() {
  if (isUpdate == null) return //  æµè§ç¶æè¿åã
  //  éªè¯æ¥è¡¨æ¯å¦å­å¨ã
  if (this.currentCell == null || this.currentCell.RowIndex == null) {
    alert('è¯·åéæ©è¦è°æ´è¡é«çè¡ã')
    return false
  }

  WidthHeightOkBtn.setVisible(true)
  WidthHeightCancelBtn.setVisible(true)

  WidthHeightOkBtn.onClickFunction = 'modifySegmentRowHeight'
  WidthHeightCancelBtn.onClickFunction = 'cancelModifySegmentRowHeight'

  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]
  var cell = segment.Rows[this.currentCell.RowIndex].Cells[this.currentCell.ColumnIndex]

  $('OldWidthHeight').setValue(cell.Height)
  $('OldWidthHeight').setEnable(false)

  $('NewWidthHeight').setValue(null)

  var dialogConfig = { Title: 'è°æ´è¡é«', Target: $('RowColumnWidthHeightSetDiv'), Width: 220, Height: 100, Function: null, IsModal: true }
  Dialog.open(dialogConfig)
  $('NewWidthHeight').focus()
}

//  ä¿®æ¹å½åè¡é«ã
function modifySegmentRowHeight() {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]
  var cell = segment.Rows[this.currentCell.RowIndex].Cells[this.currentCell.ColumnIndex]

  var newValue = $('NewWidthHeight').getValue(true, true)
  if (newValue == null) return false

  //  è·ååå¼ä¸æ°å¼å·®å¼ã
  var dValue = ET.sub(newValue, cell.Height)
  if (dValue == 0) {
    alert('å¼æªåçååã')
    return false
  }

  //  ä¿®æ¹è®¾è®¡å¨å±ç¤ºææã
  //  å½åæ ¼æå¨åçå®½åº¦é½æç§è¯¥å¼è¿è¡ååã
  //  è¢«åå¹¶çæ ¼ä¹å°å®½åº¦æç§æ°å¼å¤çã
  //  è¢«åå¹¶çæ ¼æå¨éç¹çæ ¼å®½åº¦æç§æ°çå¼è¿è¡å¢å æèåå°ã
  var modifyArchor = []
  for (var i = 0; i < segment.Rows[cell.RowIndex].Cells.length; i++) {
    var tempCell = segment.Rows[cell.RowIndex].Cells[i]
    tempCell.Height = ET.sum(tempCell.Height, dValue)
    if (tempCell.IsAnchor) {
      modifyArchor.push(tempCell.RowIndex + '_' + tempCell.ColumnIndex)
    }
    if (tempCell.IsMerge) {
      //  å¯¹åºçéç¹éè¦å¤çã
      if (!modifyArchor.contains(tempCell.AnchorX + '_' + tempCell.AnchorY)) {
        var anchorCell = segment.Rows[tempCell.AnchorX].Cells[tempCell.AnchorY]
        anchorCell.Height = ET.sum(anchorCell.Height, dValue)
        var anchroCellElement = $(getCellID(segment.Rows[anchorCell.RowIndex].Cells[anchorCell.ColumnIndex]))
        anchroCellElement.style.height = anchorCell.Height + 'mm'
      }
    } else {
      var cellElement = $(getCellID(segment.Rows[tempCell.RowIndex].Cells[tempCell.ColumnIndex]))
      cellElement.style.height = tempCell.Height + 'mm'
    }
  }

  var dialogConfig = { Title: 'è°æ´è¡é«', Target: $('RowColumnWidthHeightSetDiv'), Width: 220, Height: 100, Function: null, IsModal: true }
  Dialog.close(dialogConfig)
}
//  å³é­è°æ´è¡é«æèåå®½çªå£ã
function cancelModifySegmentRowHeight() {
  var dialogConfig = { Title: 'è°æ´è¡é«', Target: $('RowColumnWidthHeightSetDiv'), Width: 220, Height: 100, Function: null, IsModal: true }
  Dialog.close(dialogConfig)
}

//  è°æ´å½åéä¸­ååå®½ã
//  å¼¹åºåå®½ ä¿®æ¹çªå£
function modifyColumnWidth() {
  if (isUpdate == null) return //  æµè§ç¶æè¿åã
  //  éªè¯æ¥è¡¨æ¯å¦å­å¨ã
  if (this.currentCell == null || this.currentCell.RowIndex == null) {
    alert('è¯·åéæ©è¦è°æ´åå®½çåã')
    return false
  }

  WidthHeightOkBtn.setVisible(true)
  WidthHeightCancelBtn.setVisible(true)

  WidthHeightOkBtn.onClickFunction = 'modifySegmentColumnWidth'
  WidthHeightCancelBtn.onClickFunction = 'cancelModifySegmentColumnWidth'

  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]
  var cell = segment.Rows[this.currentCell.RowIndex].Cells[this.currentCell.ColumnIndex]

  $('OldWidthHeight').setValue(cell.Width)
  $('OldWidthHeight').setEnable(false)

  $('NewWidthHeight').setValue(null)

  var dialogConfig = { Title: 'è°æ´åå®½', Target: $('RowColumnWidthHeightSetDiv'), Width: 220, Height: 100, Function: null, IsModal: true }
  Dialog.open(dialogConfig)
  $('NewWidthHeight').focus()
}

// è°æ´å½åéä¸­ååå®½ã
function modifySegmentColumnWidth() {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]
  var cell = segment.Rows[this.currentCell.RowIndex].Cells[this.currentCell.ColumnIndex]

  var newValue = $('NewWidthHeight').getValue(true, true)
  if (newValue == null) return false

  //  è·ååå¼ä¸æ°å¼å·®å¼ã
  var dValue = ET.sub(newValue, cell.Width)
  if (dValue == 0) {
    alert('å¼æªåçååã')
    return false
  }

  //  ä¿®æ¹è®¾è®¡å¨å±ç¤ºææã
  //  å½åæ ¼æå¨åçå®½åº¦é½æç§è¯¥å¼è¿è¡ååã
  //  è¢«åå¹¶çæ ¼ä¹å°å®½åº¦æç§æ°å¼å¤çã
  //  è¢«åå¹¶çæ ¼æå¨éç¹çæ ¼å®½åº¦æç§æ°çå¼è¿è¡å¢å æèåå°ã
  var modifyArchor = []
  for (var i = 0; i < segment.Rows.length; i++) {
    var tempCell = segment.Rows[i].Cells[cell.ColumnIndex]
    tempCell.Width = ET.sum(tempCell.Width, dValue)
    if (tempCell.IsAnchor) {
      modifyArchor.push(tempCell.RowIndex + '_' + tempCell.ColumnIndex)
    }
    if (tempCell.IsMerge) {
      //  å¯¹åºçéç¹éè¦å¤çã
      if (!modifyArchor.contains(tempCell.AnchorX + '_' + tempCell.AnchorY)) {
        var anchorCell = segment.Rows[tempCell.AnchorX].Cells[tempCell.AnchorY]
        anchorCell.Width = ET.sum(anchorCell.Width, dValue)
        var anchroCellElement = $(getCellID(segment.Rows[anchorCell.RowIndex].Cells[anchorCell.ColumnIndex]))
        anchroCellElement.style.width = anchorCell.Width + 'mm'
      }
    } else {
      var cellElement = $(getCellID(segment.Rows[tempCell.RowIndex].Cells[tempCell.ColumnIndex]))
      cellElement.style.width = tempCell.Width + 'mm'
    }
  }
  var dialogConfig = { Title: 'è°æ´åå®½', Target: $('RowColumnWidthHeightSetDiv'), Width: 220, Height: 100, Function: null, IsModal: true }
  Dialog.close(dialogConfig)
}

//  æ ¼å¼å·
function patternBrush() {
  if (isUpdate == null) return //  æµè§ç¶æè¿åã
  //  æä½ctrlé®ã
  if (event.ctrlKey) {
    initBrushAttr()
    var dialogConfig = { Title: 'æ ¼å¼å·è®¾ç½®', Target: $('PatternBrushSetDiv'), Width: 230, Height: 310, Function: setBrushAttr, IsModal: true }
    Dialog.open(dialogConfig)
    return
  }
  //  éªè¯æ¯å¦éä¸­äºååæ ¼ã
  if (this.currentCell.RowIndex == null || this.currentCell.ColumnIndex == null) {
    alert('è¯·åéä¸­ååæ ¼åï¼åä½¿ç¨ååæ ¼æ ¼å¼å·åè½ã')
    return
  }
  var btnObj = $('brushBtn')
  if (btnObj.isRightClick == null) {
    //  æå­éä¸­çååæ ¼å¯¹è±¡
    this.copyCellStyle(false)
    $('ContentDiv').style.cursor = 'crosshair'
  } else {
    cencelCopyCellStyle(btnObj)
  }
}

//  æ ¼å¼å·å³é®äºä»¶
function patternBrushMulti() {
  if (isUpdate == null) return //  æµè§ç¶æè¿åã
  //  éªè¯æ¯å¦éä¸­äºååæ ¼ã
  if (this.currentCell.RowIndex == null || this.currentCell.ColumnIndex == null) {
    alert('è¯·åéä¸­ååæ ¼åï¼åä½¿ç¨ååæ ¼æ ¼å¼å·åè½ã')
    return
  }

  //  æå­éä¸­çååæ ¼å¯¹è±¡
  this.copyCellStyle(true)

  $('ContentDiv').style.cursor = 'crosshair'
  $('messageDiv').style.display = 'block'
}

//  å¤å¶æ ¼å¼å·æ ·å¼
function copyCellStyle(isRightClick) {
  var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]
  var cell = segment.Rows[this.currentCell.RowIndex].Cells[this.currentCell.ColumnIndex]
  //  è·åè¢«å¤å¶ååæ ¼
  var copyCell = { Border: {}, Font: {}, Padding: {}}
  //  è¾¹çº¿æ ·å¼ã
  copyCell.Border.Top = cell.Border.Top
  copyCell.Border.Bottom = cell.Border.Bottom
  copyCell.Border.Left = cell.Border.Left
  copyCell.Border.Right = cell.Border.Right

  //    copyCell.BorderTop = cell.BorderTop;
  //    copyCell.BorderBottom = cell.BorderBottom;
  //    copyCell.BorderLeft = cell.BorderLeft;
  //    copyCell.BorderRight = cell.BorderRight;
  //  å­ä½æ ·å¼ã
  copyCell.Font.Bold = cell.Font.Bold
  copyCell.Font.Italic = cell.Font.Italic
  copyCell.Font.Name = cell.Font.Name
  copyCell.Font.Size = cell.Font.Size
  copyCell.Font.Strikeout = cell.Font.Strikeout
  copyCell.Font.Underline = cell.Font.Underline

  //    copyCell.FontBold = cell.FontBold;
  //    copyCell.FontItalic = cell.FontItalic;
  //    copyCell.FontName = cell.FontName;
  //    copyCell.FontSize = cell.FontSize;
  //    copyCell.FontStrikeout = cell.FontStrikeout;
  //    copyCell.FontUnderline = cell.FontUnderline;
  //  çç½æ ·å¼ã
  copyCell.Padding.Top = cell.Padding.Top
  copyCell.Padding.Bottom = cell.Padding.Bottom
  copyCell.Padding.Left = cell.Padding.Left
  copyCell.Padding.Right = cell.Padding.Right

  //    copyCell.PaddingTop = cell.PaddingTop;
  //    copyCell.PaddingBottom = cell.PaddingBottom;
  //    copyCell.PaddingLeft = cell.PaddingLeft;
  //    copyCell.PaddingRight = cell.PaddingRight;
  //  ååæ ¼æ ·å¼ã
  copyCell.BackColor = cell.BackColor //  èæ¯è²ã
  //    copyCell.CellTextAlign = cell.CellTextAlign; //  æ¾ç¤ºçææ¬çå¯¹é½æ¹å¼ã
  copyCell.ForeColor = cell.ForeColor //  åæ¯è²ã
  copyCell.Width = cell.Width //  å®½ã
  copyCell.Height = cell.Height //  é«ã
  copyCell.TextAlign = cell.TextAlign //  å¯¹é½æ¹å¼ã

  var btnObj = $('brushBtn')
  btnObj.copyCell = copyCell
  btnObj.isRightClick = isRightClick
}

//  è®¾ç½®æ ¼å¼å·å¤å¶å±æ§ã
function setBrushAttr() {
  var brushAttr = $('brushBtn').BrushAttr

  if (brushAttr == null) {
    return
  }

  for (var cakeName in brushAttr) {
    var currValue = $(cakeName).getValue()
    brushAttr[cakeName] = currValue
  }
  UI.CC.setData(brushSetCookies, brushSetCakes)
}

//  åå§åæ ¼å¼å·å±æ§ã
function initBrushAttr() {
  legend1.onclick = clicklegend.bind(legend1)
  legend2.onclick = clicklegend.bind(legend2)
  legend3.onclick = clicklegend.bind(legend3)
  legend4.onclick = clicklegend.bind(legend4)
  var brushAttr = { BrushBorderTop: null, BrushBoderBottom: null, BrushBoderLeft: null, BrushBoderRight: null,
    BrushFontBold: null, BrushFontItalic: null, BrushFontName: null, BrushFontSize: null, BrushFontStrikeout: null, BrushFontUnderline: null,
    BrushPaddingTop: null, BrushPaddingBottom: null, BrushPaddingLeft: null, BrushPaddingRight: null,
    BrushBackColor: null, BrushTextAlign: null, BrushForeColor: null, BrushWidth: null, BrushHeight: null
  }

  var brushObj = $('brushBtn')
  if (brushObj.BrushAttr != null) {
    brushAttr = brushObj.BrushAttr
  } else {
    for (var cakeName in brushAttr) {
      $(cakeName).setValue(true)
      brushAttr[cakeName] = true
    }
    brushObj.BrushAttr = brushAttr
  }
  UI.CC.getData(brushSetCookies, brushSetCakes)
}
function clicklegend() {
  switch (this.id) {
    case 'legend1':
      var brushBorderTop = $('BrushBorderTop')
      brushBorderTop.setValue(!brushBorderTop.getValue())
      var brushBoderBottom = $('BrushBoderBottom')
      brushBoderBottom.setValue(!brushBoderBottom.getValue())
      var brushBoderLeft = $('BrushBoderLeft')
      brushBoderLeft.setValue(!brushBoderLeft.getValue())
      var brushBoderRight = $('BrushBoderRight')
      brushBoderRight.setValue(!brushBoderRight.getValue())
      break
    case 'legend2':
      var brushFontBold = $('BrushFontBold')
      brushFontBold.setValue(!brushFontBold.getValue())
      var brushFontItalic = $('BrushFontItalic')
      brushFontItalic.setValue(!brushFontItalic.getValue())
      var brushFontName = $('BrushFontName')
      brushFontName.setValue(!brushFontName.getValue())
      var brushFontSize = $('BrushFontSize')
      brushFontSize.setValue(!brushFontSize.getValue())
      var brushFontStrikeout = $('BrushFontStrikeout')
      brushFontStrikeout.setValue(!brushFontStrikeout.getValue())
      var brushFontUnderline = $('BrushFontUnderline')
      brushFontUnderline.setValue(!brushFontUnderline.getValue())
      break
    case 'legend3':
      var brushPaddingTop = $('BrushPaddingTop')
      brushPaddingTop.setValue(!brushPaddingTop.getValue())
      var brushPaddingBottom = $('BrushPaddingBottom')
      brushPaddingBottom.setValue(!brushPaddingBottom.getValue())
      var brushPaddingLeft = $('BrushPaddingLeft')
      brushPaddingLeft.setValue(!brushPaddingLeft.getValue())
      var brushPaddingRight = $('BrushPaddingRight')
      brushPaddingRight.setValue(!brushPaddingRight.getValue())
      break
    case 'legend4':
      var brushBackColor = $('BrushBackColor')
      brushBackColor.setValue(!brushBackColor.getValue())
      var brushTextAlign = $('BrushTextAlign')
      brushTextAlign.setValue(!brushTextAlign.getValue())
      var brushForeColor = $('BrushForeColor')
      brushForeColor.setValue(!brushForeColor.getValue())
      var brushWidth = $('BrushWidth')
      brushWidth.setValue(!brushWidth.getValue())
      var brushHeight = $('BrushHeight')
      brushHeight.setValue(!brushHeight.getValue())
      break
  }
}
//  ç²è´´æ ¼å¼å·æ ·å¼
function pasteCellStyle() {
  var btnObj = $('brushBtn')
  var copyCell = btnObj.copyCell
  if (copyCell != null) {
    var segment = this.report.Pages[this.currentPageIndex][this.getSegmentPositionName(this.currentSegment.SegmentPosition)][this.currentSegment.SegmentIndex]
    var cell = segment.Rows[this.currentCell.RowIndex].Cells[this.currentCell.ColumnIndex]

    var cellElement = getCellObject(cell)

    //  æ¥è¯¢æ ¼å¼å·è®¾ç½®ã
    var brushAttr = btnObj.BrushAttr
    if (brushAttr == null) { }

    //  ä¿®æ¹ååæ ¼å¯¹è±¡å±æ§ã
    //  ä¿®æ¹é¡µé¢ååæ ¼æ ·å¼ã

    //  è¾¹çº¿æ ·å¼ã
    if (brushAttr == null || brushAttr.BrushBorderTop) {
      cell.Border.Top = copyCell.Border.Top
      //            cell.BorderTop = copyCell.BorderTop;
      cellElement.style.borderTop = '#000 ' + cell.Border.Top + 'mm solid'
    }

    if (brushAttr == null || brushAttr.BrushBoderBottom) {
      cell.Border.Bottom = copyCell.Border.Bottom
      //            cell.BorderBottom = copyCell.BorderBottom;
      cellElement.style.borderBottom = '#000 ' + cell.Border.Bottom + 'mm solid'
    }

    if (brushAttr == null || brushAttr.BrushBoderLeft) {
      cell.Border.Left = copyCell.Border.Left
      //            cell.BorderLeft = copyCell.BorderLeft;
      cellElement.style.borderLeft = '#000 ' + cell.Border.Left + 'mm solid'
    }

    if (brushAttr == null || brushAttr.BrushBoderRight) {
      cell.Border.Right = copyCell.Border.Right
      //            cell.BorderRight = copyCell.BorderRight;
      cellElement.style.borderRight = '#000 ' + cell.Border.Right + 'mm solid'
    }

    //  å­ä½æ ·å¼ã
    if (brushAttr == null || brushAttr.BrushFontBold) {
      cell.Font.Bold = copyCell.Font.Bold
      //            cell.FontBold = copyCell.FontBold;
      cellElement.style.fontWeight = (cell.Font.Bold) ? 'bold' : 'normal'
    }

    if (brushAttr == null || brushAttr.BrushFontItalic) {
      cell.Font.Italic = copyCell.Font.Italic
      //            cell.FontItalic = copyCell.FontItalic;
      cellElement.style.fontStyle = (cell.Font.Italic) ? 'italic' : 'normal'
    }

    if (brushAttr == null || brushAttr.BrushFontName) {
      cell.Font.Name = copyCell.Font.Name
      //            cell.FontName = copyCell.FontName;
      cellElement.style.fontFamily = cell.Font.Name
    }

    if (brushAttr == null || brushAttr.BrushFontSize) {
      cell.Font.Size = copyCell.Font.Size
      //            cell.FontSize = copyCell.FontSize;
      cellElement.style.fontSize = cell.Font.Size + 'mm'
    }

    if (brushAttr == null || brushAttr.BrushFontStrikeout) {
      cell.Font.Strikeout = copyCell.Font.Strikeout
      //            cell.FontStrikeout = copyCell.FontStrikeout;
      cellElement.style.textDecoration = 'line-through'
    }

    if (brushAttr == null || brushAttr.BrushFontUnderline) {
      cell.Font.Underline = copyCell.Font.Underline
      //            cell.FontUnderline = copyCell.FontUnderline;
      if (brushAttr == null || brushAttr.BrushFontStrikeout) {
        cellElement.style.textDecoration = 'underline line-through'
      } else {
        cellElement.style.textDecoration = 'underline'
      }
    }
    if (brushAttr == null) {
      if (!cell.Font.Strikeout && !cell.Font.Underline) {
        cellElement.style.textDecoration = 'none'
      }
    } else {
      if (brushAttr.BrushFontUnderline && brushAttr.BrushFontStrikeout) {
        if (!cell.Font.Strikeout && !cell.Font.Underline) {
          cellElement.style.textDecoration = 'none'
        }
      }
    }
    //  çç½æ ·å¼ã
    if (brushAttr == null || brushAttr.BrushPaddingTop) {
      cell.Padding.Top = copyCell.Padding.Top
      //            cell.PaddingTop = copyCell.PaddingTop;
      cellElement.style.paddingTop = cell.Padding.Top + 'mm'
    }

    if (brushAttr == null || brushAttr.BrushPaddingBottom) {
      cell.Padding.Bottom = copyCell.Padding.Bottom
      //            cell.PaddingBottom = copyCell.PaddingBottom;
      cellElement.style.paddingBottom = cell.Padding.Bottom + 'mm'
    }

    if (brushAttr == null || brushAttr.BrushPaddingLeft) {
      cell.Padding.Left = copyCell.Padding.Left
      //            cell.PaddingLeft = copyCell.PaddingLeft;
      cellElement.style.paddingLeft = cell.Padding.Left + 'mm'
    }

    if (brushAttr == null || brushAttr.BrushPaddingRight) {
      cell.Padding.Right = copyCell.Padding.Right
      //            cell.PaddingRight = copyCell.PaddingRight;
      cellElement.style.paddingRight = cell.Padding.Right + 'mm'
    }

    //  ååæ ¼æ ·å¼ã
    if (brushAttr == null || brushAttr.BrushBackColor) {
      cell.BackColor = copyCell.BackColor //  èæ¯è²ã
      cellElement.style.backgroundColor = cell.BackColor
    }

    if (brushAttr == null || brushAttr.BrushTextAlign) {
      // cell.CellDiagonal = copyCell.CellDiagonal; //  æ°æ®ä¸ºç©ºæ¶ç»å¶æçº¿æ¹å¼ã
      cell.TextAlign = copyCell.TextAlign //  å¯¹é½æ¹å¼ã
      setAlignment(cellElement, cell.TextAlign)
    }

    if (brushAttr == null || brushAttr.BrushForeColor) {
      cell.ForeColor = copyCell.ForeColor //  åæ¯è²ã
      cellElement.style.color = cell.ForeColor
    }

    if (brushAttr == null || brushAttr.BrushWidth) {
      cell.Width = copyCell.Width //  å®½ã
      cellElement.style.width = cell.Width + 'mm'
    }

    if (brushAttr == null || brushAttr.BrushHeight) {
      cell.Height = copyCell.Height //  é«ã
      cellElement.style.height = cell.Height + 'mm'
    }
    //  éå³é®ç¹å»çæ ¼å¼å·ï¼ç¹å»ä¸æ¬¡åéæ¾å¤å¶ã
    if (!btnObj.isRightClick) {
      cencelCopyCellStyle(btnObj)
    }
  }
}

//  åæ¶æ ¼å¼å·å¤å¶
function cencelCopyCellStyle(btnObj) {
  btnObj.copyCell = null
  btnObj.isRightClick = null
  $('ContentDiv').style.cursor = 'default'
  $('messageDiv').style.display = 'none'
}

//  å³é­è°æ´è¡é«æèåå®½çªå£ã
function cancelModifySegmentColumnWidth() {
  var dialogConfig = { Title: 'è°æ´åå®½', Target: $('RowColumnWidthHeightSetDiv'), Width: 220, Height: 100, Function: null, IsModal: true }
  Dialog.close(dialogConfig)
}

